<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/3/31 11:15
 */

namespace App\Controller;


use App\Constants\System\HttpCode;
use App\Traits\ApiResponseTrait;
use Hyperf\Context\Context;

class ApiController extends AbstractController
{

    use ApiResponseTrait;


    /**
     * 请求成功
     * @param array $data
     * @param string $message
     */
    public function responseOk(array $data = [], $message = 'success')
    {
        return $this->success($data,$message);
    }

    /**
     * 请求失败.
     * @param string $message
     * @param int $code
     */
    public function responseFail($message = 'Request error!', int $code = HttpCode::BAD_REQUEST)
    {

        return $this->fail($message, $code);
    }
    /**
     * 协程上下文
     * @param $name
     * @return bool|mixed
     */
    public function __get($name){
        return Context::get(static::class.':'.$name);
    }

    /**
     * 协程上下文
     * @param $name
     * @param $value
     */
    public function __set($name,$value)
    {
        Context::set(static::class.':'.$name,$value);
    }
}